package part3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * J5Ex12SortStrings 
 *   Example of use of Collections.sort for Programmer-defined objects
 *   
 * @author tony
 */

class A implements Comparable<A>{
	private int id;
	private String name;
	public A(){ id = 0; name = "None"; }
	public A(int i, String n){ id = i; name = n; }
	public String toString(){ return id + ", " + name; }
	public int compareTo(A o) {
		return id - o.id;
	}
}
public class J5Ex13Comparable {

	public static void main(String[] args){
		List<A> list = new ArrayList<A>();
		list.add(new A( 90, "Hello") );
		list.add(new A( 8000, "Story") );
		list.add(new A( 423, "Good" ) );
		list.add(new A( -10,  "Bye"  ) );

		/*
		 * Iterator for loop
		 */
		for (Iterator<A> i = list.iterator(); i.hasNext(); )
			System.out.println( i.next() );

		System.out.println( "\n\nAnd in sorted order:");
		Collections.sort( list );

		for (A a : list)
			System.out.println( a );
	}
}
